{% extends "base.html" %}
{%block title%}
文件夹列表
{%endblock%}

{% block content %}
<div class="page-header">
  <h1>文件夹
  <small>
    {%if dir%}
    <a href="{% url "vdir:detail" dir.id %}">{{dir.get_full_path}}</a>
    {%else%}根目录
    {%endif%}
  </small>
  </h1>
</div>
<div class="btn-toolbar">
    {% if dir.parent%}
    <a class="btn btn-primary" href="{% url "vdir:detail" dir.parent.id %}">上级目录</a>
    {%else%}
    <a class="btn btn-primary" href="{% url "vdir:detail" %}">上级目录</a>
    {%endif%}
    {%if dir%}
      <a class="btn btn-primary" href="{% url "vdir:create" dir.id %}">添加子目录</a>
    {%else%}
      <a class="btn btn-primary" href="{% url "vdir:create"  %}">添加子目录</a>
    {%endif%}
    {%if dir%}
      <a class="btn btn-primary" href="{% url "vfile:create" dir.id %}">添加文件</a>
    {%endif%}
    {%if dir%}
      <a class="btn btn-primary" href="{% url "vdir:rename" dir.id %}">
        重命名
      </a>
    {%endif%}
</div>
{%if dir%}
<div class="page-header">
  <h1>文件
  </h1>
</div>
<div class="well">
    <table class="table">
      <thead>
        <tr>
          <th>id</th>
          <th>文件名</th>
          <th>版本</th>
          <th>文件路径</th>
          <th>checksum</th>
          <th>创建时间</th>
          <th>更新时间</th>
          <th style="width: 36px;"></th>
        </tr>
      </thead>
      <tbody>
      {%for f in dir.vfile_set.all%}
        <tr>
          <td>{{f.id}}</td>
          <td>{{f.name}}</td>
          <td>{{f.ver}}</td>
          <td><a href="{{f.get_url}}">{{f.get_full_path}}</a></td>
          <td>{{f.checksum}}</td>
          <td>{{f.create_date}}</td>
          <td>{{f.update_date}}</td>
          <td><a data-toggle="modal" href="#myModal" type="button" class="btn btn-primary" onclick="setid({{f.id}});">删除</a></td>
        </tr>
        {%endfor%}
      </tbody>
    </table>
</div>
{%endif%}
<div class="page-header">
  <h1>子目录
  </h1>
</div>
<div class="well">
    <table class="table">
      <thead>
        <tr>
          <th>id</th>
          <th>文件夹名</th>
          <th>版本</th>
          <th>子文件夹个数</th>
          <th>文件个数</th>
          <th>创建时间</th>
          <th>更新时间</th>
          <th style="width: 36px;"></th>
        </tr>
      </thead>
      <tbody>
      {%for subdir in subdirs.object_list%}
        <tr>
          <td><a href="{% url "vdir:detail" subdir.id %}">{{subdir.id}}</a></td>
          <td><a href="{% url "vdir:detail" subdir.id %}">{{subdir.name}}</a></td>
          <td>{{subdir.ver}}</td>
          <td>{{subdir.vdir_set.count}}</td>
          <td>{{subdir.vfile_set.count}}</td>
          <td>{{subdir.create_date}}</td>
          <td>{{subdir.update_date}}</td>
          <td><a data-toggle="modal" href="#myModal1" type="button" class="btn btn-primary" onclick="setid1({{subdir.id}});">删除</a></td>
        </tr>
        {%endfor%}
      </tbody>
    </table>
</div>

<ul class="pagination">

  {% for i in pages %}

    {% if forloop.first %}
        {% if i > 5 %}
          <li><a href="#">&laquo;</a></li>
        {% endif %}
    {% endif %}
    
    {% if i == subdirs.number %}
      <li class="active" ><a href="?page={{i}}">{{i}}</a></li>
    {%else%}
      <li><a href="?page={{i}}">{{i}}</a></li>
    {%endif%}
    {% if  forloop.last %} 
        {% if i < subdir.count %}
         <li><a href="#">&raquo;</a></li>
        {%endif%}
    {% endif %}
  {% endfor %} 
</ul>

 <!-- Modal -->
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">提示</h4>
        </div>
        <div class="modal-body">
            你是否确定删除文件？
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
          <a type="button" class="btn btn-primary" onclick="del();">确定</a>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->

    <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">提示</h4>
        </div>
        <div class="modal-body">
            你是否确定删除文件夹？
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
          <a type="button" class="btn btn-primary" onclick="del1();">确定</a>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
  {% endblock %}



  {%block js%}
  var delid = 1;
  var delid1 = 1;
  function del()
  {
    //window.open('/vfile/delete/'+delid);
     window.location = '/vfile/delete/'+delid;
  }

  function setid(id){
    delid = id;
  }

  var delid1 = 1;
  function del1()
  {
    //window.open('/vfile/delete/'+delid);
     window.location = '/vdir/delete/'+delid1;
  }

  function setid1(id){
    delid1 = id;
  }
  {%endblock%}

